/* Copyright ©, 2023, ECARX (Hubei) Technology Co., Ltd. All rights reserved.
 *
 * NOTICE: This file contains information which is confidential and proprietary
 * to ECARX (Hubei) Technology Co., Ltd. and/or other developers. No license to
 * any intellectual property rights contained within this file is either granted
 * or implied except as may be provided in an agreement with ECARX (Hubei)
 * Technology Co., Ltd.
 *
 * Any unauthorized copying or distribution of content from this file in whole
 * or in part is prohibited.
 */

#define LOG_TAG "PKI_HAL"
#include <log/log_main.h>

#include "PKIHalManager.h"
#include "hidl/Status.h"

namespace vendor::ecarx::xma::pki::V1_0::implementation {

PKIHALManager::PKIHALManager(PKIHal *pkiHal) : mPKIHal(pkiHal) {}

Return<void> PKIHALManager::readCertification(readCertification_cb _hidl_cb)
{
  StatusCode status;
  auto cert = mPKIHal->readCertificate(&status);
  _hidl_cb(status, cert);
  return Void();
}

Return<void> PKIHALManager::readSWK3Certificate(const hidl_string& filename, 
  readSWK3Certificate_cb _hidl_cb)
{
  StatusCode status;
  auto cert = mPKIHal->readSWK3Certificate(filename, &status);
  _hidl_cb(status, cert);
  return Void();
}

Return<StatusCode> PKIHALManager::updatePKIInstallStatus(PKIInstallPlatform clientId,InstallStatus status)
{
  ALOGW("%s unsupport", __FUNCTION__);
  // auto code = mPKIHal->updatePKIInstallStatus(clientId, status);
  return Return<StatusCode>(StatusCode::OK);
}

Return<void>
PKIHALManager::getSecurityInfoChecksum(getSecurityInfoChecksum_cb _hidl_cb)
{
  ALOGW("%s unsupport", __FUNCTION__);
  // auto data = mPKIHal->readSecurityInfoChecksum();
  hidl_vec<uint8_t> checksum={};
  // if (!data.empty()) {
  //   checksum = data;
  // }
  _hidl_cb(StatusCode::OK, checksum);
  return Void();
}
Return<StatusCode> PKIHALManager::writeBlock(int32_t offset,
                                             const hidl_vec<int8_t> &value)
{
  ALOGW("%s unsupport", __FUNCTION__);
  // StatusCode status = mPKIHal->writeBlock(offset, value);
  return Return<StatusCode>(StatusCode::OK);
}
} // namespace vendor::ecarx::xma::pki::V1_0::implementation